package org.hbmjpa.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="table_AccountBean")
public class AccountBean {
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid.hex")
	@Column(name="Id")
	private String id;
	
	private Boolean status=Boolean.TRUE;// 记录状态 0 无效，1 有效 
	
	private String acctNo;
	
	private double balance;
	
	/**
	 * @ManyToOne FetchType.LAZY:默认值采用延时加载,FetchType.EAGER:立即加载关联对象, CascadeType.MERGE:级联更新, CascadeType.PERSIST:级联保存 , CascadeType.REMOVE：级联删除 ,CascadeType.ALL级联以上所有
	 * @JoinColumn联接列:多的这端外键字段
	 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="userBeanId")
	private UserBean userBean;
	public AccountBean(){
		
	}
	public AccountBean(String acctNo,double balance){
		this.acctNo=acctNo;
		this.balance=balance;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getAcctNo() {
		return acctNo;
	}
	public void setAcctNo(String acctNO) {
		this.acctNo= acctNO;
	}
	public double getBalance() {
		return balance;
	}
	public void setBal(double bal) {
		this.balance = bal;
	}
	public UserBean getUser() {
		return userBean;
	}
	public void setUser(UserBean userBean) {
		this.userBean = userBean;
	}
	public void deposite(double amount) {
		balance = balance + amount;
	}

	public void withdraw(double amount) {
		balance = balance - amount;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((acctNo == null) ? 0 : acctNo.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		AccountBean other = (AccountBean) obj;
		if (acctNo == null) {
			if (other.acctNo != null){
				return false;
			}
		} else if (!acctNo.equals(other.acctNo)){
			return false;
		}
		return true;
	}
	
	public Boolean getStatus() {
		return status;
	}
	public void setStatus(Boolean status) {
		this.status = status;
	}
	public UserBean getUserBean() {
		return userBean;
	}
	public void setUserBean(UserBean userBean) {
		this.userBean = userBean;
	}
	public void setBalance(double balance) {
		this.balance = balance;
	}
	
}
